<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/layuimini/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">上传图片</label>
        <div class="layui-input-block">
            <input type="hidden" name="image" value="" class="layui-input image">
            <image src="" style="display: none;" width="100px" class="showImage"/>
            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">上传视频</label>
        <div class="layui-input-block">
            <input type="text" name="video" value="" class="layui-input video">
            <button type="button" class="layui-btn" id="test2">
                <i class="layui-icon">&#xe67c;</i>上传视频
            </button>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">上传文件</label>
        <div class="layui-input-block">
            <input type="text" name="file" value="" class="layui-input file">
            <button type="button" class="layui-btn" id="test3">
                <i class="layui-icon">&#xe67c;</i>上传文件
            </button>
        </div>
    </div>
</div>
<script src="/static/admin/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            $ = layui.$;

        //上传图片
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,accept: 'image'
            ,url: "{:url('upload.Api/uploadImage')}" //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.code == 200){
                    //图片显示
                    $('.showImage').show();
                    $('.showImage').attr({'src':res.data.fileurl});
                    //赋值
                    $('.image').val(res.data.fileurl);
                }else{
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });

        //上传视频
        var uploadInst = upload.render({
            elem: '#test2' //绑定元素
            ,accept: 'video'
            ,url: "{:url('upload.Api/uploadVideo')}" //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.code == 200){
                    //赋值
                    $('.video').val(res.data.fileurl);
                }else{
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });

        //上传文件
        var uploadInst = upload.render({
            elem: '#test3' //绑定元素
            ,accept: 'file'
            ,url: "{:url('upload.Api/uploadFile')}" //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.code == 200){
                    //赋值
                    $('.file').val(res.data.fileurl);
                }else{
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });

    });
</script>
</body>
</html>